package com.android.hedgehog.puzzles;

import java.util.Random;

public class SeesawBoard {
	public int totalBoxes;
	public SeesawBlock[] blocks;
	Random rand;
	int finalDiff; 
	int currentDiff;
	public String[] test;
	public int[] counter = new int[6];
	int pos, kg;

	public SeesawBoard(int difficulty) {
		rand = new Random();
		hardness(difficulty);
		blocks = new SeesawBlock[totalBoxes];
		configureBlocks();
		test = new String[totalBoxes+1];
		for(int i=0;i<blocks.length;i++){
			test[i] += "" +i;
			test[i]+= ":  pos:";
			test[i] += blocks[i].posValue;
			test[i]+= ":  weight:";
			test[i] += blocks[i].weight;
			test[i]+= ":  value:";
			test[i] += blocks[i].value;
			test[i]+= ":  xPos:";
			test[i] += blocks[i].xPos;
			test[i]+= ":  yPos:";
			test[i] += blocks[i].yPos;
			test[i]+= "  : total:";
			test[i]+= counter[blocks[i].xPos];
		}
		test[totalBoxes]+= currentDiff+ "  <>  "+finalDiff;
	}

	private void configureBlocks() {
		do{
			currentDiff=0;
		for (int i = 0; i < blocks.length; i++) {
			pos=rand.nextInt(6);
			kg=rand.nextInt(3);
			blocks[i]=new SeesawBlock(pos,kg);
			currentDiff+=blocks[i].value;
		}
		}while(Math.abs(currentDiff)>finalDiff);
		
		for(int i=0;i<blocks.length;i++){
			blocks[i].yPos=counter[blocks[i].xPos];
			counter[blocks[i].xPos]++;
		}

	}

	private void hardness(int difficulty) {
		totalBoxes = 10 + ((difficulty - 1) % 5); // 5=14; 6=10; 10=14;
		finalDiff = 5;
	}

}
